package com.dz.lm.web.controller.user;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.dz.lm.common.exception.ServiceException;
import com.dz.lm.common.util.FileUploadUtil;
import com.dz.lm.common.util.IdCardUtil;
import com.dz.lm.common.util.ScanCodeUtil;
import com.dz.lm.common.utils.json.JsonUtils;
import com.dz.lm.service.goldagent.GoldAgentService;
import com.dz.lm.service.manager.ManagerService;
import com.dz.lm.service.moneyBar.MoneyBarService;
import com.dz.lm.service.reminder.ReminderService;
import com.dz.lm.web.controller.BasicControl;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Vector;

@RestController
@RequestMapping(value = "/rewriteUrl/manager", produces = "application/json")
public class ManagerController extends BasicControl {

	public Logger logger = LogManager.getLogger(ManagerController.class);
	
    @Autowired
    private ManagerService managerService;
    
    @Autowired
    private MoneyBarService moneyBarService;
    
    @Autowired
    private ReminderService reminderService;

	@Autowired
	private GoldAgentService goldAgentService;
    
    /**
     * 实名认证
     * 
     * @return
     * @throws IOException
     */
    @ResponseBody
    @RequestMapping("/authRealName")
    public Map<String, Object> authRealName(HttpServletRequest request) throws ServiceException {
		String reqData = request.getAttribute("reqData") != null ? request.getAttribute("reqData").toString() : "";
    	JSONObject _reqData = JSONObject.parseObject(reqData);
    	Map<String, Object> param = JsonUtils.readValue(_reqData.toString());
    	JSONObject subjo = null;
    	//参数校验
		Vector<String> inparam = new Vector<String>();
		inparam.add("userName");
		inparam.add("idCardNo");
		for (String in : inparam) {
			if (!_reqData.containsKey(in)) {
				subjo = new JSONObject();
		    	subjo.put("result", "01");
		    	subjo.put("message", "参数" + in + "异常");
		    	return parameterEncrypt(request, subjo);
			} else if (param.get(in) == null) {
				subjo = new JSONObject();
		    	subjo.put("result", "02");
		    	subjo.put("message", "参数" + in + "不能为空");
		    	return parameterEncrypt(request, subjo);
			}
		}
		
		String userName = param.get("userName").toString();
		String idCardNo = param.get("idCardNo").toString();
		if (!IdCardUtil.validateIdCard(idCardNo)) {
			subjo = new JSONObject();
	    	subjo.put("result", "03");
	    	subjo.put("message", "身份证号码格式错误");
	    	return parameterEncrypt(request, subjo);
		}
		Map<String, Object> qryParam = new HashMap<String, Object>();
		//Token
		qryParam.put("accessToken", param.get("accessToken"));
		qryParam.put("userName", userName);
		qryParam.put("idCardNo", idCardNo);
		// 调用第三方接口 进行实名认证
		//TODO
		//认证通过 更新认证信息至数据库
		qryParam.put("userId", request.getAttribute("userId"));
		int count = managerService.updateAuthUserInfo(qryParam);
		subjo = new JSONObject();
		if (count == 1) {
			subjo.put("result", "00");
	    	subjo.put("message", "实名认证通过");
	    	subjo.put("authFlag", "1");
		} else {
			subjo.put("result", "01");
	    	subjo.put("message", "实名认证失败");
	    	subjo.put("authFlag", "0");
		}
		return parameterEncrypt(request, subjo);
    }
    
    /**
     * 钱吧认证
     * 
     * @return
     * @throws IOException
     */
    @ResponseBody
    @RequestMapping("/orgAuthManager")
    public Map<String, Object> orgAuthManager(HttpServletRequest request) throws ServiceException {
		String reqData = request.getAttribute("reqData") != null ? request.getAttribute("reqData").toString() : "";
    	JSONObject _reqData = JSONObject.parseObject(reqData);
    	Map<String, Object> param = JsonUtils.readValue(_reqData.toString());
    	JSONObject subjo = null;
    	//参数校验
		Vector<String> inparam = new Vector<String>();
		inparam.add("moneyBarId");
		for (String in : inparam) {
			if (!_reqData.containsKey(in)) {
				subjo = new JSONObject();
		    	subjo.put("result", "01");
		    	subjo.put("message", "参数" + in + "异常");
		    	return parameterEncrypt(request, subjo);
			} else if (param.get(in) == null) {
				subjo = new JSONObject();
		    	subjo.put("result", "02");
		    	subjo.put("message", "参数" + in + "不能为空");
		    	return parameterEncrypt(request, subjo);
			}
		}
		param.put("userId", request.getAttribute("userId"));
		param.put("state", "0");
		int count = managerService.orgAuthManager(param);
		subjo = new JSONObject();
		if (count == 1) {
			subjo.put("result", "00");
	    	subjo.put("message", "钱吧认证提交成功");
	    	subjo.put("barId", param.get("moneyBarId"));
	    	Map<String, Object> insertParam = new HashMap<String, Object>();
	    	param.put("barId", param.get("moneyBarId"));
	    	Map<String, Object> moneyBar = moneyBarService.getMoneyBarStateById(param);
	    	insertParam.put("userId", moneyBar.get("createUserId"));
	    	insertParam.put("type", "1");
	    	insertParam.put("operatedUserId", request.getAttribute("userId"));
	    	reminderService.addReminder(insertParam);
	    	insertParam.put("platform", param.get("platform"));
            String pushTitle = "【微介】经理人认证审批提醒";
            String pushContent = "您有新的经理人认证申请记录待受理，请注意查收";
            insertParam.put("pushTitle", pushTitle);
            insertParam.put("pushContent", pushContent);
	    	reminderService.sendMessagePush(insertParam);
		} else {
			subjo.put("result", "01");
	    	subjo.put("message", "钱吧认证提交失败");
	    	subjo.put("barId", param.get("moneyBarId"));
		}
		return parameterEncrypt(request, subjo);
    }
    
    /**
     * 搜索机构
     * 
     * @return
     * @throws IOException
     */
    @ResponseBody
    @RequestMapping("/searchMoneyBars")
    public Map<String, Object> searchMoneyBars(HttpServletRequest request) throws ServiceException {
		String reqData = request.getAttribute("reqData") != null ? request.getAttribute("reqData").toString() : "";
    	JSONObject _reqData = JSONObject.parseObject(reqData);
		Map<String, Object> param = JsonUtils.readValue(_reqData.toString());
    	JSONObject subjo = null;
    	//参数校验
		Vector<String> inparam = new Vector<String>();
		inparam.add("searchKey");
		for (String in : inparam) {
			if (!_reqData.containsKey(in)) {
				subjo = new JSONObject();
		    	subjo.put("result", "01");
		    	subjo.put("message", "参数" + in + "异常");
		    	return parameterEncrypt(request, subjo);
			} else if (param.get(in) == null) {
				subjo = new JSONObject();
		    	subjo.put("result", "02");
		    	subjo.put("message", "请输入搜索值");
		    	return parameterEncrypt(request, subjo);
			}
		}
		//searchKey	搜索条件
		String searchKey = param.get("searchKey") != null? param.get("searchKey").toString() : "";
		Map<String, Object> qryParam = new HashMap<String, Object>();
		if (!"".equals(searchKey.trim())){
			StringBuffer sb = new StringBuffer();
			searchKey = searchKey.trim();
			String key[] = searchKey.split(" ");
			for (String k : key) {
				sb.append(k);
				sb.append("%");
			}
			if (key != null && key.length > 0) {
				qryParam.put("searchKey", sb.substring(0, sb.length() - 1));
			}
		} else {
			subjo = new JSONObject();
	    	subjo.put("result", "02");
	    	subjo.put("message", "请输入搜索值");
	    	return parameterEncrypt(request, subjo);
		}
		List<Map<String, Object>> moneyBars = managerService.searchMoneyBars(qryParam);
		subjo = new JSONObject();
		subjo.put("result", "00");
    	subjo.put("message", "SUCCESS");
    	subjo.put("MoneyBars", moneyBars);
		return parameterEncrypt(request, subjo);
    }
    
    /**
     * 经理人认证
     * 
     * @return
     * @throws IOException
     */
    @ResponseBody
    @RequestMapping("/authManager")
    public Map<String, Object> authManager(HttpServletRequest request) throws ServiceException {
    	Object imgUrl = request.getAttribute("imgUrl");
    	@SuppressWarnings("unchecked")
		Map<String, Object> images = (Map<String, Object>) request.getAttribute("images");
    	Map<String, Object> urlMap = new HashMap<String, Object>();
    	if (images != null && !images.isEmpty()) {
    		urlMap = FileUploadUtil.uploadByInStream(images, imgUrl, "authManager");
    	}
		String reqData = request.getAttribute("reqData") != null ? request.getAttribute("reqData").toString() : "";
    	JSONObject _reqData = JSONObject.parseObject(reqData);
    	JSONObject subjo = null;
		Map<String, Object> param = JsonUtils.readValue(_reqData.toString());
		String idCardNo = param.get("idCardNo").toString();
		if (!IdCardUtil.validateIdCard(idCardNo)) {
			subjo = new JSONObject();
	    	subjo.put("result", "03");
	    	subjo.put("message", "身份证号码格式错误");
	    	return parameterEncrypt(request, subjo);
		}
		//用户编码
		param.put("userId", request.getAttribute("userId"));
		Set<String> keys = urlMap.keySet();
		for (String key : keys) {
			param.put(key, imgUrl + urlMap.get(key).toString());
		}
		//认证状态（0：申请中；1：审核通过，2：审核拒绝，3：未选择钱吧）
		String state = "3";
		param.put("state", state);
		//经理人认证标识（1：经理人已认证）
		param.put("manageFlag", "1");
		Map<String, Object> retData = managerService.addMoneyBarManager(param);
		if ((int)retData.get("count") == 1) {
			subjo = new JSONObject();
			subjo.put("user", retData.get("user"));
			subjo.put("result", "00");
	    	subjo.put("message", "经理人认证提交成功");
			//认证成功生成二维码
			Map map = new HashMap();
			map.put("userId", request.getAttribute("userId"));
			try {
				Map<String, Object> retCodeInfo = ScanCodeUtil.getWxScanCode(request.getAttribute("userId").toString(), ScanCodeUtil.postToken(), imgUrl);
				logger.info(JSON.toJSON(retCodeInfo)+"==================二维码参数1");

				map.put("scanCode", imgUrl + retCodeInfo.get("scanCode").toString());
				goldAgentService.applyPerStore(map);
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else {
			subjo = new JSONObject();
			subjo.put("user", null);
	    	subjo.put("result", "01");
	    	subjo.put("message", "经理人认证提交失败");
		}
		return parameterEncrypt(request, subjo);
    }
    
    /**
     * 修改经理人及机构认证信息
     * 
     * @return
     * @throws IOException
     */
    @ResponseBody
    @RequestMapping("/modifyManageAuthInfo")
    public Map<String, Object> modifyManageAuthInfo(HttpServletRequest request) throws ServiceException {
    	Object imgUrl = request.getAttribute("imgUrl");
    	@SuppressWarnings("unchecked")
		Map<String, Object> images = (Map<String, Object>) request.getAttribute("images");
    	Map<String, Object> urlMap = new HashMap<String, Object>();
    	if (images != null && !images.isEmpty()) {
    		urlMap = FileUploadUtil.uploadByInStream(images, imgUrl, "authManager");
    	}
		String reqData = request.getAttribute("reqData") != null ? request.getAttribute("reqData").toString() : "";
    	JSONObject _reqData = JSONObject.parseObject(reqData);
    	JSONObject subjo = new JSONObject();
		Map<String, Object> param = JsonUtils.readValue(_reqData.toString());
		String idCardNo = param.get("idCardNo").toString();
		if (!IdCardUtil.validateIdCard(idCardNo)) {
			subjo = new JSONObject();
	    	subjo.put("result", "03");
	    	subjo.put("message", "身份证号码格式错误");
	    	return parameterEncrypt(request, subjo);
		}
		if (param.get("userId") == null || "".equals(param.get("userId"))) {
			param.put("userId", request.getAttribute("userId"));
		}
		Set<String> keys = urlMap.keySet();
		for (String key : keys) {
			param.put(key, imgUrl + urlMap.get(key).toString());
		}
		checkImage("image",param, 6);
		param.put("validFlag", "0");
		Map<String, Object> retData = managerService.modifyManageAuthInfo(param);
		if ((int)retData.get("count") == 1) {
			//物理删除用户操作删除的图片
			deleteImages(param.get("deleteFiles"));
			subjo.put("user", retData.get("user"));
			subjo.put("result", "00");
	    	subjo.put("message", "保存成功");
		} else {
			subjo.put("user", null);
			subjo.put("result", "01");
	    	subjo.put("message", "保存失败");
		}
		return parameterEncrypt(request, subjo);
    }
    
    @ResponseBody
    @RequestMapping("/getManagerList")
    public Map<String, Object> getManagerList(HttpServletRequest request) throws ServiceException {
    	String reqData = request.getAttribute("reqData") != null ? request.getAttribute("reqData").toString() : "";
		JSONObject _reqData = JSONObject.parseObject(reqData);
		JSONObject subjo = new JSONObject();
		// 参数校验
		Vector<String> inparam = new Vector<String>();
		inparam.add("position");
		inparam.add("size");
		for (String in : inparam) {
			if (!_reqData.containsKey(in)) {
				subjo = new JSONObject();
				subjo.put("result", "01");
				subjo.put("message", "参数" + in + "异常");
				return parameterEncrypt(request, subjo);
			}
		}
		Map<String, Object> param = JsonUtils.readValue(_reqData.toString());
		String barId = param.get("barId").toString();
		String position = param.get("position") != null ? param.get("position").toString() : "";
		String size = param.get("size") != null ? param.get("size").toString() : "";
		Map<String, Object> qryParam = new HashMap<String, Object>();
		if ("".equals(position))
			position = "0";
		if ("".equals(size))
			size = "10";
		qryParam.put("barId", barId);
		qryParam.put("position", Integer.valueOf(position) * Integer.valueOf(size));
		qryParam.put("size", Integer.valueOf(size));
		qryParam.put("state", param.get("state"));
//		Map<String, Object> qryParam = new HashMap<String, Object>();
//		qryParam.put("barId", 1);
//		qryParam.put("position", Integer.valueOf("0") * Integer.valueOf("10"));
//		qryParam.put("size", Integer.valueOf("10"));
//		JSONObject subjo = new JSONObject();
		Map<String, Object> retData = managerService.getManagerList(qryParam);
		subjo.put("result", "00");
		subjo.put("message", "SUCCESS");
		subjo.put("managerList", retData.get("managerList"));
		int count = (int) retData.get("managerListCount");
		int page = 0;
		if (count % Integer.valueOf("10") > 0) {
			page = count / Integer.valueOf("10") + 1;
		} else {
			page = count / Integer.valueOf("10");
		}
		subjo.put("count", count);
		subjo.put("page", page);
		return parameterEncrypt(request, subjo);
    }
    
    @ResponseBody
    @RequestMapping("/doAuthManager")
    public Map<String, Object> doAuthManager(HttpServletRequest request) throws ServiceException {
    	String reqData = request.getAttribute("reqData") != null ? request.getAttribute("reqData").toString() : "";
    	JSONObject _reqData = JSONObject.parseObject(reqData);
    	JSONObject subjo = new JSONObject();
		Map<String, Object> param = JsonUtils.readValue(_reqData.toString());
     	param.put("auditUserId", request.getAttribute("userId"));
		int i  = managerService.doAuthManager(param);
		if (i == 1) {
			subjo.put("result", "00");
			subjo.put("message", "经理人认证审核成功");
		} else {
			subjo.put("result", "-1");
			subjo.put("message", "经理人认证审核失败");
		}
		return parameterEncrypt(request, subjo);
    }
    
    @ResponseBody
    @RequestMapping("/deleteBarManager")
    public Map<String, Object> deleteBarManager(HttpServletRequest request) throws ServiceException {
		String reqData = request.getAttribute("reqData") != null ? request.getAttribute("reqData").toString() : "";
    	JSONObject _reqData = JSONObject.parseObject(reqData);
    	JSONObject subjo = new JSONObject();
		Map<String, Object> param = JsonUtils.readValue(_reqData.toString());
//    	Map<String, Object> param = new HashMap<String, Object>();
//		JSONObject subjo = new JSONObject();
//		param.put("validFlag", "1");
//		param.put("userId", "3");
//		param.put("barId", "1");
		param.put("activeUserId", request.getAttribute("userId"));
		int i  = managerService.deleteBarManager(param);
		if (i == 1) {
			subjo.put("result", "00");
			subjo.put("message", "取消成功");
		} else {
			subjo.put("result", "-1");
			subjo.put("message", "取消失败");
		}
		return parameterEncrypt(request, subjo);
    }
    
    @ResponseBody
   	@RequestMapping("/qryBarFavoriteList")
   	public Map<String, Object> qryBarFavoriteList(HttpServletRequest request) throws ServiceException {
    	String reqData = request.getAttribute("reqData") != null ? request.getAttribute("reqData").toString() : "";
		JSONObject _reqData = JSONObject.parseObject(reqData);
		JSONObject subjo = new JSONObject();
		// 参数校验
		Vector<String> inparam = new Vector<String>();
		inparam.add("position");
		inparam.add("size");
		for (String in : inparam) {
			if (!_reqData.containsKey(in)) {
				subjo = new JSONObject();
				subjo.put("result", "01");
				subjo.put("message", "参数" + in + "异常");
				return parameterEncrypt(request, subjo);
			}
		}
		Map<String, Object> param = JsonUtils.readValue(_reqData.toString());
		String position = param.get("position") != null ? param.get("position").toString() : "";
		String size = param.get("size") != null ? param.get("size").toString() : "";
		Map<String, Object> qryParam = new HashMap<String, Object>();
		if ("".equals(position))
			position = "0";
		if ("".equals(size))
			size = "10";
		qryParam.put("userId", request.getAttribute("userId"));
		qryParam.put("position", Integer.valueOf(position) * Integer.valueOf(size));
		qryParam.put("size", Integer.valueOf(size));
//		Map<String, Object> qryParam = new HashMap<String, Object>();
//		qryParam.put("userId", 1);
//		qryParam.put("position", Integer.valueOf("0") * Integer.valueOf("10"));
//		qryParam.put("size", Integer.valueOf("10"));
//		JSONObject subjo = new JSONObject();
		Map<String, Object> retData = managerService.qryBarFavoriteListByUser(qryParam);
		subjo.put("result", "00");
		subjo.put("message", "SUCCESS");
		subjo.put("barFavoriteList", retData.get("barFavoriteList"));
		int count = (int) retData.get("barFavoriteListCount");
		int page = 0;
		if (count % Integer.valueOf("10") > 0) {
			page = count / Integer.valueOf("10") + 1;
		} else {
			page = count / Integer.valueOf("10");
		}
		subjo.put("count", count);
		subjo.put("page", page);
		return parameterEncrypt(request, subjo);
   	}
    
    @ResponseBody
	@RequestMapping("/qryApplyProductList")
	public Map<String, Object> qryApplyProductList(HttpServletRequest request) throws ServiceException {
		String reqData = request.getAttribute("reqData") != null ? request.getAttribute("reqData").toString() : "";
		JSONObject _reqData = JSONObject.parseObject(reqData);
		JSONObject subjo = new JSONObject();
		Map<String, Object> param = JsonUtils.readValue(_reqData.toString());
		
		String barId = param.get("barId").toString();
		String productId = param.get("productId").toString();
		Map<String, Object> qryParam = new HashMap<String, Object>();
		qryParam.put("barId", barId);
		qryParam.put("productId", productId);
		qryParam.put("qryState", "1");
		Map<String, Object> retData = moneyBarService.qryApplyProductList(qryParam);
		subjo.put("result", "00");
		subjo.put("message", "SUCCESS");
		subjo.put("applyProductList", retData.get("applyProductList"));
		return parameterEncrypt(request, subjo);
	}
    
    @ResponseBody
    @RequestMapping("/deleteMoneyBarAgent")
    public Map<String, Object> deleteMoneyBarAgent(HttpServletRequest request) throws ServiceException {
		String reqData = request.getAttribute("reqData") != null ? request.getAttribute("reqData").toString() : "";
    	JSONObject _reqData = JSONObject.parseObject(reqData);
    	JSONObject subjo = new JSONObject();
		Map<String, Object> param = JsonUtils.readValue(_reqData.toString());
		Integer i  = managerService.deleteMoneyBarAgent(param);
		if (i == 1) {
			subjo.put("result", "00");
			subjo.put("message", "删除成功");
		} else {
			subjo.put("result", "-1");
			subjo.put("message", "删除失败");
		}
		return parameterEncrypt(request, subjo);
    }
    
    /**
     * 添加借贷名片信息
     * 
     * @return
     * @throws IOException
     */
    @ResponseBody
    @RequestMapping("/addCreditCardInfo")
    public Map<String, Object> addCreditCardInfo(HttpServletRequest request) throws ServiceException {
    	Object imgUrl = request.getAttribute("imgUrl");
    	@SuppressWarnings("unchecked")
		Map<String, Object> images = (Map<String, Object>) request.getAttribute("images");
    	Map<String, Object> urlMap = new HashMap<String, Object>();
    	if (images != null && !images.isEmpty()) {
    		urlMap = FileUploadUtil.uploadByInStream(images, imgUrl, "creditCard");
    	}
		String reqData = request.getAttribute("reqData") != null ? request.getAttribute("reqData").toString() : "";
    	JSONObject _reqData = JSONObject.parseObject(reqData);
    	JSONObject subjo = null;
		Map<String, Object> param = JsonUtils.readValue(_reqData.toString());
		//用户编码
		param.put("userId", request.getAttribute("userId"));
		Set<String> keys = urlMap.keySet();
		for (String key : keys) {
			param.put(key, imgUrl + urlMap.get(key).toString());
		}
		//借贷名片是否已开通（0：未开通 1：已开通）
		String openCreditCardFlag = "1";
		param.put("openCreditCardFlag", openCreditCardFlag);
		int count = managerService.addCreditCardInfo(param);
		if (count > 0) {
			subjo = new JSONObject();
			subjo.put("result", "00");
	    	subjo.put("message", "添加成功");
	    	subjo.put("creditCardId", count);
		} else {
			subjo = new JSONObject();
	    	subjo.put("result", "01");
	    	subjo.put("message", "添加失败");
	    	subjo.put("creditCardId", "");
		}
		return parameterEncrypt(request, subjo);
    }
    
    /**
     * 修改借贷名片信息
     * 
     * @return
     * @throws IOException
     */
    @ResponseBody
    @RequestMapping("/updateCreditCardInfo")
    public Map<String, Object> updateCreditCardInfo(HttpServletRequest request) throws ServiceException {
    	Object imgUrl = request.getAttribute("imgUrl");
    	@SuppressWarnings("unchecked")
		Map<String, Object> images = (Map<String, Object>) request.getAttribute("images");
    	Map<String, Object> urlMap = new HashMap<String, Object>();
    	if (images != null && !images.isEmpty()) {
    		urlMap = FileUploadUtil.uploadByInStream(images, imgUrl, "creditCard");
    	}
		String reqData = request.getAttribute("reqData") != null ? request.getAttribute("reqData").toString() : "";
    	JSONObject _reqData = JSONObject.parseObject(reqData);
    	JSONObject subjo = null;
		Map<String, Object> param = JsonUtils.readValue(_reqData.toString());
		//用户编码
		param.put("userId", request.getAttribute("userId"));
		Set<String> keys = urlMap.keySet();
		for (String key : keys) {
			param.put(key, imgUrl + urlMap.get(key).toString());
		}
		checkImage("image",param, 9);
		int count = managerService.updateCreditCardInfo(param);
		if (count == 1) {
			//物理删除用户操作删除的图片
			deleteImages(param.get("deleteFiles"));
			subjo = new JSONObject();
			subjo.put("result", "00");
	    	subjo.put("message", "修改成功");
		} else {
			subjo = new JSONObject();
	    	subjo.put("result", "01");
	    	subjo.put("message", "修改失败");
		}
		return parameterEncrypt(request, subjo);
    }
    
    /**
     * 查询借贷名片信息
     * 
     * @return
     * @throws IOException
     */
    @ResponseBody
    @RequestMapping("/qryCreditCardInfo")
    public Map<String, Object> qryCreditCardInfo(HttpServletRequest request) throws ServiceException {
		String reqData = request.getAttribute("reqData") != null ? request.getAttribute("reqData").toString() : "";
    	JSONObject _reqData = JSONObject.parseObject(reqData);
    	JSONObject subjo = null;
		Map<String, Object> param = JsonUtils.readValue(_reqData.toString());
		//用户编码
		param.put("userId", request.getAttribute("userId"));
		Map<String, Object> creditCardInfo = managerService.qryCreditCardInfo(param);
		if (creditCardInfo != null) {
			subjo = new JSONObject();
			subjo.put("result", "00");
	    	subjo.put("message", "查询成功");
	    	subjo.put("creditCardInfo", creditCardInfo);
		} else {
			subjo = new JSONObject();
	    	subjo.put("result", "01");
	    	subjo.put("message", "查询失败");
	    	subjo.put("creditCardInfo", null);
		}
		return parameterEncrypt(request, subjo);
    }
    
    /**
     * 预览借贷名片信息
     * 
     * @return
     * @throws IOException
     */
    @ResponseBody
    @RequestMapping("/previewCreditCardInfo")
    public Map<String, Object> previewCreditCardInfo(HttpServletRequest request) throws ServiceException {
		String reqData = request.getAttribute("reqData") != null ? request.getAttribute("reqData").toString() : "";
    	JSONObject _reqData = JSONObject.parseObject(reqData);
    	JSONObject subjo = null;
		Map<String, Object> param = JsonUtils.readValue(_reqData.toString());
		//用户编码
		param.put("userId", request.getAttribute("userId"));
		Map<String, Object> creditCardInfo = managerService.previewCreditCardInfo(param);
		if (creditCardInfo != null) {
			subjo = new JSONObject();
			subjo.put("result", "00");
	    	subjo.put("message", "查询成功");
	    	subjo.put("creditCardInfo", creditCardInfo);
		} else {
			subjo = new JSONObject();
	    	subjo.put("result", "01");
	    	subjo.put("message", "查询失败");
	    	subjo.put("creditCardInfo", null);
		}
		return parameterEncrypt(request, subjo);
    }
}
